﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Soap;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Xml.Serialization;

namespace S02
{
    class Program
    {
        static void Main(string[] args)
        {
            //var data = DateTime.Now;
            String fileName = "s.dat";

            //FileStream fs1 = new FileStream(fileName,FileMode.Create);
            //BinaryFormatter bf1 = new BinaryFormatter();
            //bf1.Serialize(fs1, data);
            //fs1.Close();

            //FileStream fs2 = new FileStream(fileName, FileMode.Open);
            //BinaryFormatter bf2 = new BinaryFormatter();
            //var a =bf2.Deserialize(fs2);
            //fs2.Close();

            //ShoppingCartItem data =new ShoppingCartItem(123,345,8);

            //FileStream fs1 = new FileStream(fileName, FileMode.Create);
            //BinaryFormatter bf1 = new BinaryFormatter();
            //bf1.Serialize(fs1, data);
            //fs1.Close();

            //FileStream fs2 = new FileStream(fileName, FileMode.Open);
            //BinaryFormatter bf2 = new BinaryFormatter();
            //var a = bf2.Deserialize(fs2);
            //fs2.Close();

            //ShoppingCartItem data = new ShoppingCartItem(123, 345, 8);

            //FileStream fs1 = new FileStream(fileName, FileMode.Create);
            //SoapFormatter bf1 = new SoapFormatter();
            //bf1.Serialize(fs1, data);
            //fs1.Close();

            //FileStream fs2 = new FileStream(fileName, FileMode.Open);
            //SoapFormatter bf2 = new SoapFormatter();
            //var a = bf2.Deserialize(fs2);
            //fs2.Close();

            //ShoppingCartItem data = new ShoppingCartItem(123, 345, 8);

            //FileStream fs1 = new FileStream(fileName, FileMode.Create);
            //XmlSerializer bf1 = new XmlSerializer(typeof(ShoppingCartItem));
            //bf1.Serialize(fs1, data);
            //fs1.Close();

            //FileStream fs2 = new FileStream(fileName, FileMode.Open);
            //XmlSerializer bf2 = new XmlSerializer(typeof(ShoppingCartItem));
            //var a = bf2.Deserialize(fs2);
            //fs2.Close();

            ShoppingCartItem data = new ShoppingCartItem(123, 345, 8);

            JavaScriptSerializer bf1 = new JavaScriptSerializer();
            var a=bf1.Serialize(data);

            JavaScriptSerializer bf2 = new JavaScriptSerializer();
            var b = bf2.Deserialize<ShoppingCartItem>(a.ToString());
  
        }
    }
    [Serializable]
    public class ShoppingCartItem
    {
        public int productId;
        public decimal price;
        public int quantity;
        public decimal total;

        public ShoppingCartItem()
        {
        }

        public ShoppingCartItem(int productId, decimal price, int quantity)
        {
            this.productId = productId;
            this.price = price;
            this.quantity = quantity;
            this.total = price* quantity;
        }
    }
}
